import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate'
import * as types from './mutation-types'
Vue.use(Vuex);
const config = {
    plugins: [createPersistedState()],
    state: {
        isLogin: false,
        username: '',
        token: '',
        // 被保人信息
        insuredInfos: [{
            relation: '1',
            userName: '',
            idNo: '',
            idType: '01',
            gender: '',
            birthDate: '',
            mobile: '',
            area: [],
            key: new Date().getTime()
        }]
    },
    getters: {
        isLogin: state => state.isLogin,
        token: state => state.token,
        username: state => state.username
    },
    mutations: {
        updateLogin(state, payload) {
            state.isLogin = payload;
        },
        updateToken(state, payload) {
            state.token = payload;
        },
        updateUsername(state, payload) {
            state.username = payload;
        },
        [types.SET_INSUREDINFOS](state, model){
            state.insuredInfos = JSON.parse(JSON.stringify(model))
        }
    },
    actions: {
        setInsuredInfos({ commit }, data={}) {
          commit(types.SET_INSUREDINFOS, data)
       }
    }
}
const store = new Vuex.Store(config);
export default store;